public class Leet35 {
    public static void main(String[] args) {
        Leet35 l = new Leet35();
        System.out.println(l.searchInsert(new int[]{1, 3},2));
    }
    public int searchInsert(int[] nums, int target) {
        int mid = nums.length/2,hi = nums.length,lo = 0;
        while (hi>lo){
            if (nums[mid]==target)
                return mid;
            else if (nums[mid]<target){
                lo = mid+1;
            }else {
                hi = mid-1;
            }
            mid = (lo+hi)/2;
        }
        return mid==nums.length?mid:nums[mid]<target?mid+1:mid;
    }
}
